package com.winning.sx.microframework.common.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class CustomDateSerializer extends JsonSerializer<Timestamp> {
    private    static     SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public void serialize(Timestamp arg0, JsonGenerator arg1, SerializerProvider arg2)
            throws IOException, JsonProcessingException {
        String formattedDate = formatter.format(arg0);
        arg1.writeString(formattedDate);
    }

    private static CustomDateSerializer _instance=null;
    public static CustomDateSerializer instance(){
        if (null==_instance){
                 _instance=new CustomDateSerializer();
        }

        return _instance;
    }


}

